package com.wfy.zxing;

import android.content.DialogInterface;
import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.app.AlertDialog;
import android.support.v7.app.AppCompatActivity;
import android.view.View;

import static com.wfy.zxing.CaptureActivity.SCAN_REQUEST;
import static com.wfy.zxing.CaptureActivity.SCAN_REQUEST_CODE;
import static com.wfy.zxing.CaptureActivity.SCAN_RESULT;

public class MainActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
    }

    public void scan(View view) {
        startActivityForResult(new Intent(this,CaptureActivity.class),SCAN_REQUEST);
    }

    @Override
    protected void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        if (requestCode==SCAN_REQUEST){
            switch (resultCode){
                case SCAN_REQUEST_CODE:
                    String scan_result=data.getStringExtra(SCAN_RESULT);
                    new AlertDialog.Builder(this)
                            .setTitle("提示信息")
                            .setMessage(scan_result)
                            .setPositiveButton("确定", new DialogInterface.OnClickListener() {
                                @Override
                                public void onClick(DialogInterface dialog, int which) {
                                    dialog.dismiss();
                                }
                            }).show();
                    break;
            }
        }
    }
}
